/**
 * Created by zhanglihe on 15/10/30.
 */
require.config(require_config);

define([
    'jquery',
    'common',
    'ready',
    'template',
    'collection',
    'model',
    'dialog'
], function( $, common, ready, template, Collection, Model, dialog ) {

    var index = function() {
        this.init();
    };
    index.prototype = {
        init: function() {
            loading();
            this.event();
            this.fetch();
        },

        fetch: function() {
            var id = getUrlPath(4);
            var _this = this;
            this.collection = new Collection({
                url: _global.url.api + 'area/order',
                condition: {id:id},
                model: {

                },
                callback: function() {
                    loaded();
                    _this.total(this.result.total);
                }
            });
            this.collection.fetch();
        },
        total: function (total) {
            $('#total').html(total);
        },
        event: function() {
            var _this = this;

            /**
             * 搜索事件
             */
            $('#btn-search').on('click', function(e) {
                e.preventDefault();
                _this.collection.condition.sn = $("input[name='sn']").val();
                _this.collection.reload();
            });
            $('#month-area').on('click', function(e) {
                e.preventDefault();
                _this.collection.condition.id = getUrlPath(4);
                delete _this.collection.condition.sn;
                _this.collection.reload();
            });
        },
    };

    new index();

});